# Copyright (c) 2008 Alvin Wang http://cloudwizard.com/
# License New BSD
# See README for additional information
"""
Amazon Web Services Cloud Support

"""

from cloudwizard.cloud import Cloud
from cloudwizard.config import Config
from ec2 import Ec2
from sqs import Sqs
import boto


class Aws(Cloud):
    """
    aws_key_pair = 'testa'
    ec2_conn = None	#?? how to encapsulate
    cloud_vartypes = ['aws_ami', 'aws_keypair', 'aws_secgroup', 'aws_ipaddr',
          'aws_disk']
    """
    cloud_name = "Amazon Web Services"
    cloud_abbrev = "aws"
    cloud_vartypes = ['aws_ami', 'aws_keypair', 'aws_secgroup', 'aws_ipaddr',
          'aws_disk']
    cloud_services = ['ec2', 'sqs', 's3', 'sdb']

    def script_auth(self, username='default'):
        """Ask for Access Id, Secrey Key, and default Key Pair 
        """
        self.cloud_auth = Config( cloud_abbrev=self.cloud_abbrev, type='user',
            autoload=False) 
        
        self.cloud_auth.prompt(question="Please enter your AWS Id", varname="aws_access_id")
            
        self.cloud_auth.prompt(question="Please enter your AWS Secret Key", varname="aws_secret_key")

        self.cloud_auth.prompt(question="What is your default key pair?", 
            varname="default_keypair")
            
        username = self.cloud_auth.prompt(question="User Name?",
            default='default', vartype="username", varname="username")
        # Add more stuff
        # get a default key or create it if necessary
        # 
        self.cloud_auth.write_config( config_name=username)
        
    def get_service(self, service=None, **args):
        """return a AWS service"""
        # could use lambda but it is more painful
        if service == "compute":
            return Ec2( auth=self.cloud_auth)
        if service == "ec2":
            return Ec2( auth=self.cloud_auth)
        if service == "queue":
            return Sqs( auth=self.cloud_auth)
        if service == "sqs":
            return Sqs( auth=self.cloud_auth)
        if service == "s3":
            return Sqs( auth=self.cloud_auth)
        # error?

    def get_auth(self, service=None, **args):
        """return a AWS service"""
        # could use lambda but it is more painful
        return self.cloud_userid,self.cloud_password

